package com.trolls.client;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ViewTrollEdit extends Content {
	private VerticalPanel vpanel;
	private CompositePortraitUi trollFace;
	private CompositeFormEditTroll compositeCompetences;
	private CompositeGalleryImg galleryTroll;
	
	public ViewTrollEdit(ArrayList<Item> listTroll) {
		super("Editer un Troll");
		VerticalPanel vPanelGallery= new VerticalPanel();
		galleryTroll = new CompositeGalleryImg(listTroll);
		vPanelGallery.add(galleryTroll);
		config((Troll)listTroll.get(0));
		vpanel.add(vPanelGallery);
		showTroll((Troll)listTroll.get(0));

		this.initWidget(vpanel);

		//Affichage de la face du premier troll
	}

	public ViewTrollEdit(Troll troll) {
		super("Créer un Troll");
		config(troll);
		showTroll(troll);
		
		this.initWidget(vpanel);

	}
	
	public ViewTrollEdit(ArrayList<Item> listTroll, Troll troll) {
		super("Editer un Troll");
		VerticalPanel vPanelGallery= new VerticalPanel();
		galleryTroll = new CompositeGalleryImg(listTroll,troll);
		vPanelGallery.add(galleryTroll);
		config(troll);
		vpanel.add(vPanelGallery);
		showTroll(troll);
		
		this.initWidget(vpanel);
	}

	private void config(Troll troll){
		serveurInfo = new HTML("");

		vpanel= new VerticalPanel();
		vpanel.add(enteteContent);
		HorizontalPanel hpanel = new HorizontalPanel();
		trollFace = new CompositePortraitUi(troll.getImagePath(),troll.getName());	//Affichage de la face du premier troll
		compositeCompetences = new CompositeFormEditTroll((Troll)troll);
		hpanel.add(trollFace);
		hpanel.add(compositeCompetences);
		vpanel.add(hpanel);
	}

	public void showTroll(Troll troll) {
		compositeCompetences.showTroll(troll);
		Image img = new Image(troll.getImagePath());
		img.addStyleName("gallery-img");
		img.setTitle(troll.getName());
		img.setAltText(troll.getName());
		trollFace.setImg(img);

	}
	
	public void SetServeurInfo(String str){
		compositeCompetences.SetServeurInfo(str);
	}
	public Item getItemEnCour() {
		// TODO Auto-generated method stub
		return compositeCompetences.getItemEnCour();
	}
	public String getNewName(){
		return trollFace.getTbName().getValue();
	}
}
